﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Threading.Tasks;
using System.Xml.Linq;
using CoreShop.Library;
using CoreShop.Model;
using CoreShop.Repository;
using SqlSugar;
using static System.Net.Mime.MediaTypeNames;
using static CoreShop.Library.GlobalEnumVars;


namespace CoreShop.Services
{
    /// <summary>
    /// 接口实现
    /// </summary>
    public class corecmstakeoutdetailServices : Repository<corecmstakeoutdetail>
    {

        /// <summary>
        /// 根据商品类型ID查询类型名称
        /// </summary>
        /// <param name="custoType"></param>
        /// <returns></returns>
        public corecmstakeoutdetail QueryById(long id)
        {
            var model = base.Change<corecmstakeoutdetail>().GetSingle(a => a.orderId == id);
            model.deliveryTimeStr = model.deliveryTime == 0 ? "立即送达" : CommFunc.ConvertTimestampToDateTime(model.deliveryTime.ToString()).ToString();
            model.title = string.Concat("#", model.daySeq.ToString(), "美团外卖");
            var remark = "顾客需要餐具";
            var dinnersNumber = model.dinnersNumber;
            if (dinnersNumber == 99)
                remark = "顾客不需要餐具";

            if (!string.IsNullOrEmpty(model.caution))
            {
                if (model.caution.Contains("收餐人隐私号"))//开通隐私号
                {
                    string[] cautions = model.caution.Split(new string[] { "收餐人隐私号" }, StringSplitOptions.RemoveEmptyEntries);
                    var realPhoneSource = string.Empty;
                    if (cautions.Length == 2)//有备注
                    {
                        remark += "," + cautions[0];
                        realPhoneSource = cautions[1];
                    }
                    else
                    {
                        realPhoneSource = cautions[0];
                    }

                    model.phone =string.Concat("手机尾号:",realPhoneSource.Substring(realPhoneSource.Length - 4));

                    //if (model.caution.Contains("****"))
                    //{
                    //    var phone = "****";
                    //    string[] cautions = model.caution.Split(new string[] { "****" }, StringSplitOptions.RemoveEmptyEntries);
                    //    if (cautions.Length == 2)
                    //    {
                    //        if (cautions[0].Length >= 3)
                    //        {
                    //            var frist = cautions[0].Substring(cautions[0].Length - 3);
                    //            phone = frist + phone;
                    //        }
                    //        if (cautions[1].Length >= 4)
                    //        {
                    //            var end = cautions[1].Substring(0, 4);
                    //            phone += end;
                    //        }
                    //    }
                    //    model.phone = phone;
                    //}

                }
                else
                {
                    remark += "," + model.caution;
                }
            }

            model.remark = remark;
            model.ctimeStr= CommFunc.ConvertTimestampToDateTime(model.ctime.ToString()).ToString();
            return model;
        }

    }
}
